package com.example.demo.controller;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.example.demo.entity.User;

/**
 * 原生API注入
 * @author mill
 *
 */
@Controller
@RequestMapping("remote")
@SessionAttributes(value={"user"},types= {String.class})//所有key为user或者类型为String的值
public class RemoteApiController {

	/**
	 * 因为在@SessionAttributes中有声明，所以Map中key为user的和String类型的值都将加入到session作用域中
	 * 而原本的request作用域依然会有这些值
	 * @param map
	 * @return
	 */
	@GetMapping("session")
	public String getUser(Map<String,Object> map) {
		map.put("user", new User("张三",8,'男',null));//注入user
		map.put("info", "桃花坞里桃花庵");//注入String类型的参数
		return "remote/testsession";
	}
	
	/**
	 * 参数注入进来的可以是一下的参数
	 * 	HttpServletRequest
		HttpServletResponse
		HttpSession
		java.security.Principal
		Locale
		InputStream
		OutputStream
		Reader
		Writer
	 * @param session
	 * @param resp
	 * @return
	 */
	@GetMapping("sess2")
	public String getUser2(HttpSession session,HttpServletResponse resp) {
		session.setAttribute("count", 88);
		return "remote/testsession";
		
	}
}
